package servlet;

import db.DB;
import model.suppliers;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/addsupply")//访问的时候给一个地址,高于3.0版本的包才能这么配地址
public class addsupply extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        resp.setHeader("content-type","text/html;charset=utf-8");
        String supplyname=req.getParameter("addsupplyname");
        String supplyphone=req.getParameter("addsupplyphone");
        String supplyinfo=req.getParameter("addsupplyinfo");

        suppliers sp=new suppliers();
        sp.setSupplier_name(supplyname);
        sp.setSupplier_phoneNumber(supplyphone);
        sp.setremarks(supplyinfo);

        String datapage = null;
        HttpSession session=req.getSession();

        if(new DB().addsupply(sp)){
            datapage = "supply";
            session.setAttribute("datapage",datapage);
            resp.sendRedirect("datasystem.jsp");
        }
        else{
            System.out.println("failed");}
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp); }
}

